The standard type hierarchy
Below is a list of the types that are built into Python. Extension
modules written in C can define additional types. Future versions of
Python may add types to the type hierarchy (e.g. rational or complex
numbers, efficiently stored arrays of integers, etc.).
datatype
typehierarchy
extensionmodule
Some of the type descriptions below contain a paragraph listing
`special attributes'. These are attributes that provide access to the
implementation and are not intended for general use. Their definition
may change in the future. There are also some `generic' special
attributes, not listed with the individual objects: __methods__
is a list of the method names of a built-in object, if it has any;
__members__
is a list of the data attribute names of a built-in
object, if it has any.
specialattribute
genericspecialattribute
__methods__
__members__
- None
- This type has a single value. There is a single object with this value.
This object is accessed through the built-in name
None
.
It is returned from functions that don't explicitly return an object.
None
None@None
- Numbers
- These are created by numeric literals and returned as results by
arithmetic operators and arithmetic built-in functions. Numeric
objects are immutable; once created their value never changes. Python
numbers are of course strongly related to mathematical numbers, but
subject to the limitations of numerical representation in computers.
number
numeric
Python distinguishes between integers and floating point numbers:
- Integers
- These represent elements from the mathematical set of whole numbers.
integer
There are two types of integers:
- Plain integers
- These represent numbers in the range -231 through 231 - 1.
(The range may be larger on machines with a larger natural word
size, but not smaller.)
When the result of an operation falls outside this range, the
exception
OverflowError
is raised.
For the purpose of shift and mask operations, integers are assumed to
have a binary, 2's complement notation using 32 or more bits, and
hiding no bits from the user (i.e., all 232 different bit
patterns correspond to different values).
plain integer
- Long integers
- These represent numbers in an unlimited range, subject to available
(virtual) memory only. For the purpose of shift and mask operations,
a binary representation is assumed, and negative numbers are
represented in a variant of 2's complement which gives the illusion of
an infinite string of sign bits extending to the left.
long integer